package com.library.control.log;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.mvc.AbstractFormController;

import com.library.model.dto.register.RegisterDTO;
import com.library.model.service.MemberService;

public class RegisterController extends AbstractFormController {
	
	private MemberService memberservice;

	
	public void setMemberservice(MemberService memberservice) {
		this.memberservice = memberservice;
	}

	@Override
	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		String member_id=request.getParameter("member_id");
		String password=request.getParameter("password");
		String name=request.getParameter("name");
		String jumin1=request.getParameter("jumin1");
		String jumin2=request.getParameter("jumin2");
		String jumin=jumin1+"-"+jumin2;
		String phone=request.getParameter("phone1")+"-"+request.getParameter("phone2")+"-"+request.getParameter("phone3");
		String email=request.getParameter("email");
		String zipcode=request.getParameter("zipcode");
		String address=request.getParameter("address");
		String detailaddress=request.getParameter("detailaddress");
		
		RegisterDTO dto=new RegisterDTO(member_id,password,name,jumin,phone,email,zipcode,address,detailaddress);
		
		return dto;
	}
	
	@Override
	protected ModelAndView processFormSubmission(HttpServletRequest request,
			HttpServletResponse response, Object arg2, BindException arg3)
			throws Exception {
		memberservice.insertRegister((RegisterDTO)arg2);
		return new ModelAndView("registerok");
	}

	@Override
	protected ModelAndView showForm(HttpServletRequest arg0,
			HttpServletResponse arg1, BindException arg2) throws Exception {
		return new ModelAndView("register");
	}

}
